var siteurl = 'http://' + window.location.host +'/';

$(function() {
	// 固定顶部登录信息
	if($("#mini-login").length>0){
		$("#mini-login").pin();
	}
	$(window).resize(function() {
		$("#mini-login").width('100%');
	});
});

// 加入书架
function addBookcase(bid){
	var bid = arguments[0] ? arguments[0] : 0;
	$.ajax({
		type: "GET",
		dataType: "json",
		url: siteurl+'addbookcase/'+bid+'.html',
		beforeSend: function(){
			loadIndex = layer.load(2, {
				shade: [0.1,'#fff'] //0.1透明度的黑色背景
			});
		},
		success: function(res) {
			if (res.status == 1) {
				layer.msg(res.msg,{icon: 1,time: 2000});
			}else{
				layer.msg(res.msg,{icon: 2,time: 2000});
			}
		},
		error: function(HttpRequest, ajaxOptions, thrownError) {
			layer.msg('网络错误，请稍候重试！',{icon: 2,time: 3000});
		},
		complete: function(){
			layer.close(loadIndex);
		}
	});
}

// 订阅章节
function subscription(bid,cid){
	var bid = arguments[0] ? arguments[0] : 0;
	var cid = arguments[1] ? arguments[1] : 0;
	$.ajax({
		type: "GET",
		dataType: "json",
		url: siteurl+'subscription/'+bid+'/'+cid+'.html',
		beforeSend: function(){
			loadIndex = layer.load(2, {
				shade: [0.1,'#fff'] //0.1透明度的黑色背景
			});
		},
		success: function(res) {
			if (res.status == 1) {
				window.location.reload();
			}else{
				layer.msg(res.msg,{icon: 2,time: 2000});
			}
		},
		error: function(HttpRequest, ajaxOptions, thrownError) {
			layer.msg('网络错误，请稍候重试！',{icon: 2,time: 3000});
		},
		complete: function(){
			layer.close(loadIndex);
		}
	});
}

// 自动订阅章节
function autoSubscription(bid, checked, no_redirect){
	var bid = arguments[0] ? arguments[0] : 0;
	var checked = checked ? 1 : 0;
	var no_redirect = no_redirect ? 1 : 0;
	$.ajax({
		type: "GET",
		dataType: "json",
		url: siteurl+'autosubscription/'+bid+'/'+checked+'.html',
		beforeSend: function(){
			loadIndex = layer.load(2, {
				shade: [0.1,'#fff'] //0.1透明度的黑色背景
			});
		},
		success: function(res) {
			if (res.status == 1) {
				layer.msg(res.msg, {icon: 1,time: 2000},function(){
					if(!no_redirect){
						window.location.reload();
					}
				});
			}else{
				layer.msg(res.msg,{icon: 2,time: 2000});
			}
		},
		error: function(HttpRequest, ajaxOptions, thrownError) {
			layer.msg('网络错误，请稍候重试！',{icon: 2,time: 3000});
		},
		complete: function(){
			layer.close(loadIndex);
		}
	});
}